package cn.vihub.service.impl;

import cn.hutool.core.lang.tree.TreeUtil;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.vihub.mapper.ShopGoodsCategoryMapper;
import cn.vihub.pojo.ShopGoodsCategory;
import cn.vihub.service.ShopGoodsCategoryService;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: 秋晚
 * @Date:  2025/7/28 19:30
 * @Description: 
 **/

@Service
@Transactional(rollbackFor = Exception.class)
public class ShopGoodsCategoryServiceImpl extends ServiceImpl<ShopGoodsCategoryMapper, ShopGoodsCategory> implements ShopGoodsCategoryService{

    @Autowired
    ShopGoodsCategoryMapper shopGoodsCategoryMapper;
    @Override
    public Object getTree() {
        //查询所有数据
        List<ShopGoodsCategory> shopGoodsCategories = shopGoodsCategoryMapper.selectList(null);
        //组装树状结构
        return TreeUtil.build(shopGoodsCategories,"0",(shopGoodsCategory,tree)->{
            tree.setId(shopGoodsCategory.getId()+"");
            tree.setName(shopGoodsCategory.getName());
            tree.setParentId(shopGoodsCategory.getPid()+"");
            tree.putExtra("level",shopGoodsCategory.getLevel());
        });
    }
}
